package com.example.container.join;

/**
 * Created by ZMJ on 2019/12/29.
 */
public class JoinThread1 extends Thread {

    private JoinThread2 thread2;

    public JoinThread1(JoinThread2 thread2, String name) {
        super(name);
        this.thread2 = thread2;
    }

    @Override
    public void run() {
        for (int i = 0; i <= 10; i++) {
            System.out.println(Thread.currentThread().getName() + "打印" + i);
            if (i == 5) {
                try {
                    thread2.start();
                    thread2.join();//强行加入
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

}
